const Model = require('../model/article/list');

module.exports = app => {

    return class HomeController extends app.Controller {

        async index() {
            const { ctx, config } = this;
            const data = Object.assign(
                Model.getPage(1, 10),
                config.seo, {
                    action: 'home',
                    title: 'test'
                });
            // console.log(data);
            await ctx.render('home/index/index.js', data);
        }

        async tags() {
            const { ctx, config } = this;
            const data = Object.assign(
                Model.getPage(1, 10),
                config.seo, {
                    action: 'tags',
                    title: 'test'
                });
            await ctx.render('home/tags/index.js', data);
        }

        async archives() {
            const { ctx, config } = this;
            const data = Object.assign(
                Model.getPage(1, 10),
                config.seo, {
                    action: 'archives',
                    title: 'test'
                });
            await ctx.render('home/archives/index.js', data);
        }

        async about() {
            const { ctx, config } = this;
            const data = Object.assign(
                Model.getPage(1, 10),
                config.seo, {
                    action: 'about',
                    title: 'test'
                });
            await ctx.render('home/about/index.js', data);
        }

        async search() {
            const { ctx } = this;
            await ctx.render('home/index/index.js', Model.getPage(1, 10));
        }

        async page() {
            const { ctx } = this;
            const pageIndex = ctx.query.pageIndex;
            const pageSize = ctx.query.pageSize;
            ctx.body = Model.getPage(pageIndex, pageSize);
        }

        async post() {
            const { ctx } = this;
            await ctx.render('home/post/index.js', Model.getPage(1, 10));
        }
    };
};
